<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>赠送优惠券</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <style>
        .box{
            width: 800px;
        }
        .layui-btn{
            float: right;
            margin-right: 20px;
        }
    </style>
</head>
<body>
<div class="box">
    <div style="margin:30px 0px 0px 5px">
        <input type="text" class="layui-input-inline" style="height: 27px;" placeholder="优惠券名称" name="couponName" id="couponName"/><i onclick="search()" class="layui-icon layui-icon-search" style="position: absolute;left:155px;top:38px;"></i>
    </div>
    <div style="width: 800px; height: 400px;">
        <div id="tableDemo" lay-filter="tableDemo"></div>
    </div>
</div>

<input name="userId" id="userId" type="hidden"/>

</body>
<script>
    layui.use(["table","layer"],function () {
        var table = layui.table;
        var layer = layui.layer;

        var param = {
            "":"",
            "":"",
            "":""
        };
        selectUserCoupon(param);
        search = function search(){
            var couponName = $("#couponName").val();
            var param = {
                "couponName":couponName,
                "":"",
                "":""
            };
            selectUserCoupon(param)

        }
        function selectUserCoupon(param){
            $.ajax({
                url:"/JsUserCoupon/getAllJsUserCoupon",
                data:param,
                type:'post',
                dataType:'json',
                success:function (data) {
                    showTable(data.data);
                }
            });
        }

        function showTable(data){
            table.render({
                elem:"#tableDemo",
                data:data,
                width:1000,
                cols:[[
                    {type:'checkbox'},
                    {field:"couponName",title:"优惠券名称",align:"center",width:190},
                    {field:"couponPrice",title:"优惠金额",align:"center",width:190},
                    {field:"type",title:"使用类型",align:"center",width:190,templet:function (data) {
                            if (data.type == 2){
                                return "商品";
                            } else{
                                return "视频";
                            }
                        }},
                    {field:"startDate",title:"开始时间",align:"center",width:190},
                    {field:"endDate",title:"到期时间",align:"center",width:184}
                ]],
                page:true

            });

            table.on("checkbox(tableDemo)",function (obj) {
                localStorage.setItem("couponId",obj.data.couponId);
            });

        }

        //现在时间
        function getTime(){
            var date=new Date();
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hour=date.getHours();
            var minute=date.getMinutes();
            var second=date.getSeconds();
            var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
            return dateStr;
        }

        function zeroFilling(data){
            if(data<10){
                data="0"+data;
            }
            return data;
        }

    })
</script>
</html>